package find.chat.test;

import java.io.UnsupportedEncodingException;

import android.app.Activity;
import android.app.Instrumentation;
import android.app.Instrumentation.ActivityMonitor;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.test.suitebuilder.annotation.SmallTest;
import find.chat.*;
import find.chat.R;
import find.chat.types.FriendInfo;
import android.view.KeyEvent;
import android.view.Menu;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Toast;
import android.test.TouchUtils;
import android.test.ActivityInstrumentationTestCase2;

public class addfriend extends ActivityInstrumentationTestCase2<AddFriend> {
	private AddFriend mActivity;
	EditText username;
	Button add,cancel;

	public addfriend() {
		super(AddFriend.class);
	}

	protected void setUp() throws Exception {
		// this method is called every time before any test execution
		super.setUp();

		mActivity = (AddFriend) getActivity(); // get current activity
		Thread loginThread = new Thread() {
			@Override
			public void run() {
				String result = null;
				try {
					result = mActivity.mImService.authenticateUser("chung",
							"12345");
				} catch (UnsupportedEncodingException e) {

					e.printStackTrace();
				}

			}
		};
		loginThread.start();
		// link the objects with the activity objects
		
		username = (EditText) mActivity.findViewById(R.id.newFriendUsername);
		cancel = (Button) mActivity.findViewById(R.id.cancel);
		add = (Button) mActivity.findViewById(R.id.addFriend);
		mActivity.mImService.addNewFriendRequest("test1","12345","chung");
	}

	@SmallTest
	// SmallTest: this test doesn't interact with any file system or network.
	public void testView() { // checks if the activity is created
		assertNotNull(getActivity());
	}

	public void testingadd1() {
		TouchUtils.tapView(this, username);
		sendKeys("P E T E R");
		TouchUtils.clickView(this, add);
		assertEquals("peter",username.getText().toString());
	}
	public void testingadd2() {
		TouchUtils.tapView(this, username);
		sendKeys("T E S T 1");
		TouchUtils.clickView(this, add);
		assertEquals("test1",username.getText().toString());
	}public void testingaddNoName() {
		TouchUtils.clickView(this, add);
	}
	public void testingcancel() {
		TouchUtils.tapView(this, username);
		sendKeys("H I H I");
		TouchUtils.clickView(this, cancel);
		assertEquals("hihi",username.getText().toString());
	}
}
